#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
	int ans=0,f=1;
	char c=getchar();
	while(!isdigit(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c)){
		ans=(ans<<1)+(ans<<3)+(c^48);
		c=getchar();
	}
	return ans*f;
}

int t,n,a[200010],dp[200010],ans;

void dfs(int s){
	if(s>n){
		int x=-1,y=-1,cnt=0;
		for(int i=1;i<=n;++i){
			if(dp[i]==1){
				if(x!=-1) cnt+=(a[x]==a[i]?a[x]:0);
				x=i;
			}
			if(dp[i]==2){
				if(y!=-1) cnt+=(a[y]==a[i]?a[y]:0);
				y=i;
			}
		}
		ans=max(ans,cnt);
		return ;
	}
	dp[s]=1;
	dfs(s+1);
	dp[s]=2;
	dfs(s+1);
	dp[s]=0;
}

signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	t=read();
	while(t--){
		n=read();
		for(int i=1;i<=n;++i) a[i]=read();
		ans=0;
		dfs(1);
		printf("%lld\n",ans);
	}
	return 0;
}

